/**
*   FuzzyEngine - an Simple flex framework 
*   Copyright (C) 2010 Constantin Aldea
*
*   This program is free software: you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package fuzzy.penelope.core.dataservices.rest {
	import flash.net.URLRequestMethod;
	import mx.controls.Alert;
	import mx.managers.CursorManager;
	import mx.rpc.AsyncToken;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	public class FuzzyService extends HTTPService
	{
		
		
		public function FuzzyService(rootURL:String=null, destination:String=null)
		{
			super(rootURL, destination);
			useProxy = false;
			method = URLRequestMethod.POST;
			contentType=CONTENT_TYPE_XML;
			resultFormat=RESULT_FORMAT_E4X;
			//serializationFilter = new LispaSerializationFilter;
		}

		public var host:String;
		
		public function callLocalHttpService(nomeFile:String, listner:Function):AsyncToken
		{
			useProxy = false;
			method = URLRequestMethod.POST;
			contentType=CONTENT_TYPE_XML;
			resultFormat=RESULT_FORMAT_E4X;
			url	=  "debug/"+nomeFile;
			//trace(url);
			requestTimeout = 240;
			CursorManager.setBusyCursor();	
			addEventListener(ResultEvent.RESULT, listner );
			addEventListener(FaultEvent.FAULT, faultResult );
			return send( );
		}
		
		public function callFuzzyServices(nomeModuloFuzzy:String, nomeServizioFuzzy:String, input:Object=null,  listner:Function=null, setCursor:Boolean=true):AsyncToken
		{
			useProxy = false;
			method = URLRequestMethod.POST;
			contentType=CONTENT_TYPE_XML;
			resultFormat=RESULT_FORMAT_E4X;
			url	=  host + "/" + nomeModuloFuzzy + "/" + nomeServizioFuzzy;
			trace("url : " + url );
			requestTimeout = 240;
			
			if(setCursor) CursorManager.setBusyCursor();	
			if(listner != null) addEventListener(ResultEvent.RESULT, listner );
			addEventListener(FaultEvent.FAULT, faultResult );
			return send( input );
		}
		
		
		private function faultResult(event : FaultEvent) : void {
			CursorManager.removeAllCursors();
			//Context.getInstance().contextLoader.removeLoading();
			//Alert.show(AppConfigKeyEnum.MSG_ERRORE_COMUNICAZIONE_SERVER,AppConfigKeyEnum.MSG_ATTENZIONE);
		}
	}
}